package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.mall.api.dto.MallOrderDTO;
import com.alpha.eceasy.mall.api.entity.MallCommodityDetail;
import com.alpha.eceasy.mall.api.entity.MallOrder;
import com.alpha.eceasy.mall.api.vo.MallOrderVO;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.service.MallOrderService;
import com.alpha.eceasy.mall.service.impl.MallOrderServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/order")
@Tag(description = "order", name = "订单（需求单）")
public class MallOrderController {
    private final MallOrderServiceImpl mallOrderService;

    /**
     * 分页查询-根据条件筛选
     *
     * @param dto dto
     * @return 分页结果
     */
    @GetMapping("")
    @Operation(description = "分页查询-默认查看当前登录用户", summary = "分页查询-根据条件筛选")
    public R<IPage<MallOrderVO>> pageOrderVO(@RequestParam("pageNum") Integer pageNum,
                                             @RequestParam("pageSize") Integer pageSize,
                                             MallOrderDTO dto) {
        return R.ok(mallOrderService.pageOrderVO(Page.of(pageNum, pageSize), dto));
    }

    /**
     * 通过guid查询订单详情
     *
     * @param guid guid
     * @return R 返回结果
     */
    @GetMapping("/{guid}")
    @Operation(description = "通过guid查询订单详情", summary = "通过guid查询订单详情")
    public R<MallOrderVO> getDetailVOByGuid(@PathVariable("guid") String guid,
                                            @RequestParam(value = "offererGuid",required = false) String offererGuid) {
        return R.ok(mallOrderService.getDetailVOByGuid(guid,offererGuid));
    }

    /**
     * 新增订单
     *
     * @param dto 订单
     * @return R 返回结果
     */
    //@SysLog("新增订单")
    @PostMapping
    @Operation(description = "新增订单", summary = "新增订单")
    public R<Boolean> save(@RequestBody MallOrderDTO dto) {
        return R.ok(mallOrderService.saveDTO(dto));
    }

    /**
     * 修改订单
     *
     * @param dto 订单
     * @return R 返回结果
     */
    //@SysLog("修改订单")
    @PutMapping
    @Operation(description = "根据guid修改订单", summary = "根据guid修改订单")
    public R<Boolean> updateById(@RequestBody MallOrderDTO dto) {
        return R.ok(mallOrderService.updateDTOByGuid(dto));
    }
}
